package NdkTest.main;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.KeyEvent;

public class NdkActivity extends Activity {
	private OpenGLView		m_openGLView;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        // 縦横の固定
        controlOrientationFix( true );

        m_openGLView =  new OpenGLView( this );

        // 画面にセット
        setContentView( m_openGLView );
    }

    @Override
	public void finish()
    {
    	super.finish();

    	// ビューの終了処理
    	m_openGLView.finish();
    }

	/**
	 *
	 * @param event
	 * @return
	 */
	@Override
	public boolean dispatchKeyEvent(KeyEvent event)
	{

		return false;
	}

	@Override
	public void onDestroy()
	{
		
	}


    /**
	 * 縦横固定の設定をActivityに適用する
	 *
	 * @param fixOrient 固定するならtrue，回転するように戻すならfalse
	 */
	private void controlOrientationFix( boolean fixOrient )
	{
		if (fixOrient) {
			int ori = getResources().getConfiguration().orientation;
			if (ori == Configuration.ORIENTATION_LANDSCAPE) {
				setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
			} else {
				setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
			}
		} else {
			setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED );
		}
	}
	
	/**
	 * レジューム
	 */
	@Override
	protected void onResume()
	{
		super.onResume();
		
		m_openGLView.onResume();
	}
}